﻿<html>
<head>
<title>Testing Framework Demo page</title>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8">
<script type="text/javascript" src="../../html/html.js"></script>
<script type="text/javascript" src="../jsflow.js"></script>
<script type="text/javascript" src="calc.js"></script>
<script type="text/javascript" src="flowTest.js"></script>

<script type="text/javascript">
function $(id){return document.getElementById(id);}

function write(msg){
	$("out").innerHTML+="<br>"+msg;
}

var calc = new Calc();
function extend(o,s){for(var k in s)o[k]=s[k];}

FlowTest.panelID = "out";

with(JSFlow){with(FlowTest){
	new Test("Простой тест калькулятора", sequence(
		function(){var go = new Continuation();
			calc.add(2, 3, function(r){assert(r, 4, go.block); go();});
		},
		sequence(
			function(){var go = new Continuation();
				calc.add(2, 3, function(r){assert(r, 4, go.block); go();});
			},
			function(){var go = new Continuation();
				calc.add(2, 3, function(r){assert(r, 4, go.block); go();});
			}
		),
		function(){var go = new Continuation();
			calc.sub(2, 3, function(r){assert(r, 4, go.block); go();});
		},
		function(){
			(new Continuation())();
		},
		function(){var go = new Continuation();
			calc.mul(2, 3, function(r){assert(r, 6, go.block); go();});
		}
	));
	
	new Test("Disabled Test", sequence(
		wait(100),
		wait(100),
		function(){var go = new Continuation();
			assert(1, 0, go.block);
			go();
		},
		wait(100),
		function(){var go = new Continuation();
			assert(1, 1, go.block);
			go();
		},
		wait(100)
	), false);
	
	new Test("Еще один тест калькулятора", sequence(
		function(){var go = new Continuation();
			calc.mul(2, 3, function(r){assert(r, 6, go.block); go();});
		},
		function(){var go = new Continuation();
			calc.sub(2, 3, function(r){assert(r, 1, go.block); go();});
		},
		function(){var go = new Continuation();
			calc.add(2, 3, function(r){assert(r, 5, go.block); go();});
		}
	));
	
	new Test("Сложный вложенный тест", sequence(
		function(){var go = new Continuation();
			calc.mul(2, 3, function(r){assert(r, 6, go.block); go();});
		},
		sequence(
			function(){var go = new Continuation();
				calc.sub(2, 3, function(r){assert(r, 1, go.block); go();});
			},
			sequence(
				function(){var go = new Continuation();
					calc.sub(2, 3, function(r){assert(r, 1, go.block); go();});
				},
				function(){var go = new Continuation();
					calc.add(2, 3, function(r){assert(r, 5, go.block); go();});
				}
			),
			function(){var go = new Continuation();
				calc.add(2, 3, function(r){assert(r, 5, go.block); go();});
			}
		)
	));
	
	new Test("Сложный вложенный тест с параллельным участком", sequence(
		function(){var go = new Continuation();
			calc.mul(2, 3, function(r){assert(r, 6, go.block); go();});
		},
		sequence(
			function(){var go = new Continuation();
				calc.sub(2, 3, function(r){assert(r, 1, go.block); go();});
			},
			parallel(
				function(){var go = new Continuation();
					calc.sub(2, 3, function(r){assert(r, -1, go.block); go();});
				},
				function(){var go = new Continuation();
					calc.add(2, 3, function(r){assert(r, 5, go.block); go();});
				}
			),
			function(){var go = new Continuation();
				calc.add(2, 3, function(r){assert(r, 5, go.block); go();});
			}
		)
	));

	
}}

function init(){
	FlowTest.runAll();
}
</script>
</head>
<body onload="init()">
	<h1>Testing Framework Demo page</h1>
	<p>Пример построения простой оболочки для тестирования асинхронных процессов.</p>
	<p>Для включения/выключения отдельных тестов можно задавать специальные ключи в командной строке, например:</p>
	<div>
		demo.htm#+1,2 - включены тесты 1 и 2<br>
		demo.htm#-2 - выключен тест 2
	</div>
	<p>Если среда тестирования не реагирует на данные ключи, следует нажать &lt;Ctrl+F5&gt;</p>
	
	<div id="logPnl"></div>
	<div id="out"></div>
</body>
</html>